<template>
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="dialogFormVisible" width="65vw" @close="close"
    :append-to-body="true">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">


      <el-row :gutter="10">
        <el-col :span="8">
          <el-form-item label="品种名称" prop="wuzimc">
            <el-input v-model.trim="form.wuzimc" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="规格型号">
            <el-input v-model.trim="form.guigexh" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="物资分类" prop="wuzizyid">

            <el-select v-model="form.wuzizyid" placeholder="请选择">
              <el-option v-for="(item, index) in Wzzylist" :key="index" :label="item.zhuanyemc"
                :value="item.zhuanyeid"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="8">
          <el-form-item label="物资类别">
            <el-select v-model="form.a" placeholder="请选择">
              <el-option v-for="(item, index) in Wzzylist" :key="index" :label="item.zhuanyemc"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->

        <!-- <el-col :span="8">
          <el-form-item label="物资代码">
            <el-input v-model.trim="form.wuzibm" autocomplete="off"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="真实编目码">
            <el-input v-model.trim="form.zhengshibmm" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="8">
          <el-form-item label="系列号">
            <el-input v-model.trim="form.xilieh" autocomplete="off"></el-input>
          </el-form-item>
        </el-col> -->
        <!-- <el-col :span="8">
          <el-form-item label="性能指标">
            <el-select v-model="form.a" placeholder="请选择">
              <el-option v-for="(item, index) in Wzzylist" :key="index" :label="item.zhuanyemc"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->


        <el-col :span="8">
          <el-form-item label="生产厂家">
            <el-input v-model.trim="form.shengchancj" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="8">
          <el-form-item label="生产日期">
            <el-date-picker v-model.trim="form.shengchanrq" size="small" type="date" value-format="yyyy-MM-dd"
              :editable="false" placeholder="请选择时间" />
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="计量单位">
            <el-input v-model.trim="form.jiliangdw" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="适用装备">
            <el-input v-model.trim="form.shiyongzb" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>


        <el-col :span="8">
          <el-form-item label="参考价格(元)">
            <el-input v-model.trim="form.cankaojg" type="number" min="0" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="净重（千克)">
            <el-input v-model.trim="form.jingzhong" type="number" min="0" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="毛重(千克)">
            <el-input v-model.trim="form.maozhong" type="number" min="0" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="保质期（月)">
            <el-input v-model.trim="form.baozhiq" type="number" min="0" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="8">
          <el-form-item label="过期时间">
            <el-input :value="$util.expireTime(form.shengchanrq, form.baozhiq)" readonly autocomplete="off"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="8">
          <el-form-item label="主管单位">
            <el-select v-model="form.zhuguandw" placeholder="请选择">
              <el-option v-for="(item, index) in zgdwlist" :key="index" :label="item.danweimc"
                :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>


        <el-col :span="8">
          <el-form-item label="包装尺寸-长(mm)">
            <el-input v-model.trim="form.baozhuangc" type="number" min="0" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="包装尺寸-宽(mm)">
            <el-input v-model.trim="form.baozhuangk" type="number" min="0" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="包装尺寸-高(mm)">
            <el-input v-model.trim="form.baozhuangg" type="number" min="0" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注">
            <el-input type="textarea" v-model="form.beizhu"></el-input>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { doEdit } from '@/api/userManagement'
import { insertKufang, updateKufang } from '@/api/cangkujichu'
import { insertWuzi, save, updateWuzi, getwuzibyID } from '@/api/wuzi'


export default {
  name: 'WarehouseManagement',
  data() {
    return {
      Wzzylist: [],
      form: {

      },
      rules: {
        wuzimc: [
          { required: true, trigger: 'blur', message: '请输入物资名称' },
        ],
        wuzizyid: [
          { required: true, trigger: 'blur', message: '请选择物资分类' },
        ],
        kufanglxid: [
          { required: true, trigger: 'blur', message: '请输入库房类型' },
        ],
        zhiliangzkid: [
          { required: true, trigger: 'blur', message: '请输入质量状况' },
        ],

        jianzhumj: [
          { required: true, trigger: 'blur', message: '请输入建筑面积' },
        ],
        shiyongmj: [
          { required: true, trigger: 'blur', message: '请输入使用面积' },
        ],
        keyongkr: [
          { required: true, trigger: 'blur', message: '请输入可用库容' },
        ],
        yiyongkr: [
          { required: true, trigger: 'blur', message: '请输入已用库容' },
        ]
      },
      title: '',
      dialogFormVisible: false,
      zhiliangzklist: [{
        id: '1',
        name: '完好'
      },
      {
        id: '2',
        name: '基本完好'
      },
      {
        id: '3',
        name: '严重损坏'
      },
      {
        id: '4',
        name: '废弃'
      }
      ],
      kufanglxlist: [{
        id: '1',
        name: '半地下库'
      }, {
        id: '2',
        name: '地面库'
      }, {
        id: '3',
        name: '洞库'
      }, {
        id: '4',
        name: '楼库'
      }
      ],
      zgdwlist: [],
    }
  },
  async mounted() {
    //物资分类
    this.Wzzylist = await this.$util.getWzzy()
    //主管单位
    this.zgdwlist = await this.$util.getZgdw()
  },
  created() { },
  methods: {
    async showEdit(row) {
      if (!row) {
        this.title = '新增物资'
      } else {
        this.title = '编辑物资'
        let { data } = await getwuzibyID({ id: row.id })
        this.form = Object.assign({}, data)
      }
      this.dialogFormVisible = true
    },
    close() {
      this.$refs['form'].resetFields()
      this.form = this.$options.data().form
      this.dialogFormVisible = false
    },
    save() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          let res = null;
          if (this.title == '新增物资') {
            res = await insertWuzi(this.form)
          } else {
            res = await updateWuzi(this.form)
          }
          this.$baseMessage(res.msg, 'success')
          this.$emit('fetch-data')
          this.close()
        } else {
          return false
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.el-select--small {
  width: 100%;
}

.el-date-editor {
  width: 100%;
}
</style>